package com.fordmotor.api;

import static com.fordmotor.cache.EhCache.cacheManager;

import com.fordmotor.pojo.GaodeObject;
import com.fordmotor.service.LbsService;
import com.fordmotor.util.MapUtil;
import net.sf.ehcache.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.TreeMap;

/**
 * @author THUNDEROBOT
 * @date 2020/07/07 12:15
 */
@RestController
@RequestMapping("/count")
public class StatisticsAPI {
    @Autowired
    private LbsService lbsService;
    /**
     * 统计某用户查询最多的福特4s店
     * @param uid
     * @return
     */
    @GetMapping("/ford")
    public GaodeObject ford(String uid) throws Exception {
        Element element = cacheManager.getCache("ford").get(uid);
        Map<String,Integer> map = (Map<String,Integer>)(element.getObjectValue());
        String maxCountId = MapUtil.valueSortedMap(new TreeMap(map));
        GaodeObject gaodeObject = lbsService.idSearch(maxCountId);
        return gaodeObject;
    }

    /**
     * 统计某用户查询最多的中国石化加油站
     * @param uid
     * @return
     */
    @GetMapping("/sinopec")
    public GaodeObject sinopec(String uid){
        Element element = cacheManager.getCache("sinopec").get(uid);
        Map<String,Integer> map =  (Map<String,Integer>)(element.getObjectValue());
        String maxCountId = MapUtil.valueSortedMap(new TreeMap(map));
        GaodeObject gaodeObject = lbsService.idSearch(maxCountId);
        return gaodeObject;
    }
}
